package com.tankgame4;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

public class TankGame04 extends JFrame {
    // 定义MyPanel
    MyPanel mp = null;

    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        TankGame04 tankGame01 = new TankGame04();
    }

    public TankGame04() {
        System.out.print("请输入选择 1、新游戏  2、继续上局： ");
        String key = scanner.next();
        mp = new MyPanel(key);
        // 启动MyPanel线程
        Thread thread = new Thread(mp);
        thread.start();
        this.add(mp);
        this.setSize(1500, 790);
        this.addKeyListener(mp);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);

        // 响应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }
}
